<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>file upload</title>
    <script>
        window.onload=function () {
            document.getElementById("file1").onchange=function () {
                checkfiletype();
            }
        }
        function checkfiletype() {
            var fi=new String(document.getElementById("file1").value);
            var xe=fi.substring(fi.lastIndexOf(".")+1);
            if(xe!="jpg"&&xe!="jpeg"&&xe!="JPEG"){
                alert("只能上传JPG格式的图像文件！")
            }
            else {
                document.getElementById("file1").accept="image/jpeg";
                document.write("文件上传中")
            }
        }
    </script>
</head>
<body>
<form>
    <label>选择文件：</label><input type="file" id="file1">
</form>
</body>
</html>